﻿using MediatR;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers
{
    public class EmployeeSearchByDidandStateHandler : IRequestHandler<EmployeeSearchByDidandState, List<PublicArray>>
    {
        private readonly IEmployeeRep employeeRep;

        public EmployeeSearchByDidandStateHandler(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }

        public async Task<List<PublicArray>> Handle(EmployeeSearchByDidandState request, CancellationToken cancellationToken)
        {
            var list =await employeeRep.GetvaluesByResult(x => x.IsDel == false && x.DepartId == request.dname && x.EmployeeStyle == request.state&&x.PostsId==request.rname);
            var lists=new List<PublicArray>();
            foreach (var item in list)
            {
                lists.Add(new PublicArray
                {
                    id = item.Eid,
                    name = item.Ename,
                });
            }
            return lists;
        }
    }
}
